package examples.codequality.infrastructure;

import examples.codequality.domain.User;
import org.springframework.stereotype.Repository;

import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

@Repository
public class UserMapper {

    private final Set<UserDO> userTable = ConcurrentHashMap.newKeySet();

    public User selectById(UUID id) {
        Optional<UserDO> first = userTable.stream().filter(user -> user.id().equals(id.toString())).findFirst();

        return first.map(UserConverter::toEntity).orElse(null);
    }

    public void create(User user) {
        userTable.add(UserConverter.toDo(user));
    }
}